package cn.cjxy.controller;

import cn.cjxy.domain.Teacher;
import cn.cjxy.service.TeacherService;
import cn.cjxy.utils.TeacherQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    /**
     * 查询所有
     * @return
     */
    @PostMapping("/findAll")
    public List<Teacher> teacherList(@RequestBody TeacherQuery query) {
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        //构造查询条件
        teacherQueryWrapper.eq("country",query.getCountry()).eq("name",query.getName());
        return   teacherService.list(teacherQueryWrapper);
    }

    @GetMapping()
    public List<Teacher> teacherListAll() {

        return   teacherService.list();
    }
    /**
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Teacher teacher(@PathVariable Integer id) {
        return   teacherService.getById(id);
    }
    /**
     *
     * @param teacher
     */
    @PostMapping
    public void save(@RequestBody Teacher teacher) {
        teacherService.save(teacher);
    }
}
